{% extends "master.html" %}
{% block subtitle %} - 财务管理 - 更新应付账单{% endblock %}

{% block extCSS %}
<style type="text/css">
    .tmp,.atmtemplate{
        display : none;
    }
</style>
{% endblock %}

{% block extJS %}
<script language="JavaScript" type="text/javascript">
//<![CDATA[
    var extAtm = [];
    {% for a in obj.attachment %}
        extAtm.push({{a.id}});
    {% endfor %}
    
    var index = 11;
    function addItem(){
        index +=1 ;
        var tmp = $(".tmp").clone();
        tmp.removeClass("tmp").addClass("done");
        $("input,textarea,select",tmp).each(function(){
            var t = $(this);
            var n = t.attr("name");
            t.attr("name",n.replace("_x","_"+index));
        });
        $("#dtls_tb").append(tmp);
    }
    
    function delItem(obj){
        var t = $(obj);
        $(t.parents("tr")[0]).remove();
    }
    
    function toSubmit(){
        $('form').submit();
    }
    
    function toCancel(){
        redirect_alert("{{MSG_LEAVE_WITHOUT_SAVING}}","{{url_for('bpFin.view',action='index_in')}}")
    }   
//]]>
</script>
{% endblock %}


{% block main %}
<div class="container">
    <div class="row">
        <ol class="breadcrumb">
          <li><a href="{{url_for('bpRoot.view')}}">基础信息</a></li>
          <li><a href="{{url_for('bpFin.view',action='index_out')}}">财务管理</a></li>
          <li class="active">更新应付账单</li>
        </ol>
    </div>
    <div class="row">
        <div class="btn-toolbar pull-right">
            <div class="btn-group"><button class="btn btn-default" onclick="addItem()">增加项目</button></div>
            <div class="btn-group"><button class="btn btn-primary" onclick="toSubmit()">{{BTN_SUBMIT}}</button></div>
            <div class="btn-group"><button class="btn btn-inverse" onclick="toCancel()">{{BTN_CANCEL}}</button></div>
        </div>
    </div>
    
    <div class="row">          
    <form class="" method='POST' action="{{url_for('bpFin.view',action='update')}}"  enctype="multipart/form-data">
        <input type="hidden" name="id" value="{{obj.id}}"/>
        <input type="hidden" name="direction" value="{{FIN_OUT}}"/>
        <input type="hidden" name="attachment" id="attachment" value="{{obj.attachment|join('|',attribute='id')}}"/>
        <fieldset>
            <legend>应付账单详情</legend>
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="refer">系统编号</label></label>
                    <div class="controls">
                        {{obj.no}}
                    </div>
                </div>
                <div class="control-group controls-row">
                    <label for="invoiceNo" class="control-label"><label for="invoiceNo">发票号码</label></label>
                    <div class="controls"><input type="text" name="invoiceNo" id="invoiceNo" value="{{obj.invoiceNo|f}}"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="issueTo" class="control-label"><label for="issueTo">开发票方</label></label>
                    <div class="controls"><input type="text" name="issueTo" id="issueTo" value="{{obj.issueTo|f}}"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="refer" class="control-label"><label for="refer">涉及</label></label>
                    <div class="controls"><input type="text" name="refer" id="refer" value="{{obj.refer|f}}"/></div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="createTime" class="control-label"><label for="createTime">开票时间</label></label>
                    <div class="controls"><input type="text" name="createTime" id="createTime" class="datepicker" value="{{obj.createTime|fd}}"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="createBy" class="control-label"><label for="createBy">经办人</label></label>
                    <div class="controls"><input type="text" name="createBy" id="createBy" value="{{obj.createBy|f}}" readonly="true"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="remark">备注</label></label>
                    <div class="controls"><textarea name="remark" id="remark">{{obj.remark|f}}</textarea></div>
                </div>               
            </div>
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="amount" class="control-label"><label for="amount">总金额<span style='color:red'>*</span></label></label>
                    <div class="controls"><input type="text" name="amount" id="amount" class="num" value="{{obj.amount}}"/></div>
                </div>
            </div> 
            <div class="col-md-12">
                <div class="control-group">
                  <label class="control-label" for="attachment">附件</label>
                  <div class="controls">
                      {{mymacros.render_edit_all_attachment(obj.attachment)}}            
                      <ul id="atmul" class="list-unstyled">
                          <li><input type="file" name="atm_10"/><a href="#" onclick="addAtm('atmtemplate','atmmk','#atmul')"><i class="glyphicon glyphicon-plus"></i></a></li>
                          <li class="atmtemplate"><input type="file" name="atm_x"/><a href="#" onclick="delAtm(this,'atmmk')"><i class="glyphicon glyphicon-minus"></i></a></li>
                      </ul>
                  </div>
                </div>                
            </div> 
            <div class="col-md-12">
                <table class="table table-bordered" id="dtls_tb">
                    <thead>
                        <tr>
                            <td>&nbsp;</td>
                            <td class="col-md-2">项目名称</td>
                            <td>项目描述</td>
                            <td class="col-md-2">单价</td>
                            <td class="col-md-1">数量</td>
                            <td class="col-md-2">金额</td>
                            <td class="col-md-2">备注</td>
                        </tr>
                    </thead>
         
                    <tbody>
                        {% for d in obj.dtls %}
                        <tr class="done">
                            <td><a href="#" onclick="delItem(this)"><i class="glyphicon glyphicon-remove"></i></a></td>
                            <td><input type="text" name="olditemName_{{d.id}}" value="{{d.itemName}}" class="col-md-2"/></td>
                            <td><textarea name="olddesc_{{d.id}}" class="col-md-2">{{d.desc|f}}</textarea></td>
                            <td><input type="text" name="oldprice_{{d.id}}" class="col-md-2" value="{{d.price}}"/></td>
                            <td><input type="text" name="oldqty_{{d.id}}" class="col-md-1 num" value="{{d.qty}}"/></td>
                            <td><input type="text" name="oldamount_{{d.id}}" class="col-md-2 num" value="{{d.amount}}"/></td>
                            <td><textarea name="oldremark_{{d.id}}" class="col-md-2">{{d.remark|f}}</textarea></td>
                        </tr>
                        {% endfor %}
                        <tr class="tmp">
                            <td><a href="#" onclick="delItem(this)"><i class="glyphicon glyphicon-remove"></i></a></td>
                            <td><input type="text" name="itemName_x" class="col-md-2"/></td>
                            <td><textarea name="desc_x" class="col-md-2"></textarea></td>
                            <td><input type="text" name="price_x" class="col-md-2"/></td>
                            <td><input type="text" name="qty_x" class="col-md-1 num"/></td>
                            <td><input type="text" name="amount_x" class="col-md-2 num"/></td>
                            <td><textarea name="remark_x" class="col-md-2"></textarea></td>
                        </tr>
                    </tbody>                
                </table>
            </div>
        </fieldset>
    </form>
    </div>
    
   
</div>
{% endblock %}